package com.itheima.api.subject;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.subject.CmsSubjectMapper;
import com.itheima.vo.pojo.CmsSubject;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

@DubboService
public class CmsSubjectServiceImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject> implements CmsSubjectService {

    @Autowired
    private CmsSubjectMapper subjectMapper;

    @DubboReference
    private CmsSubjectService subjectService;

    /**
     * 根据专题名称分页获取商品专题
     *
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public Map findPage(Integer pageNum, Integer pageSize, String keyword) {
        //创建分页构造器
        Page<CmsSubject> page = new Page<>(pageNum, pageSize);
        //创建条件构造器
        LambdaQueryWrapper<CmsSubject> lqw = new LambdaQueryWrapper<>();
        lqw.like(keyword != null, CmsSubject::getCategoryName, keyword);
        subjectService.page(page, lqw);
        Map map = new HashMap();
        map.put("list", page.getRecords());
        map.put("pageNum", pageNum);
        map.put("pageSize", pageSize);
        map.put("total", page.getTotal());
        map.put("totalPage", page.getPages());
        return map;
    }
}
